import Cookies from 'js-cookie'
const TokenKey = 'gulimall_token'
const RefreshTokenKey = 'gulimall_refresh_token'

export function getAuthToken() {
  return Cookies.get(TokenKey)
}

export function setAuthToken(token, exp) {
  exp = new Date().getTime() + Number(exp * 1000) // 秒转毫秒
  const expires = new Date(exp)
  return Cookies.set(TokenKey, token, { expires })
}

export function removeAuthToken() {
  return Cookies.remove(TokenKey)
}

export function getAuthRefreshToken() {
  return Cookies.get(RefreshTokenKey)
}

export function setAuthRefreshToken(token) {
  return Cookies.set(RefreshTokenKey, token)
}

export function removeAuthRefreshToken() {
  return Cookies.remove(RefreshTokenKey)
}
